/**
 * 将XML配置转换成对象,后期会将映射类存入服务器缓存
 * @author 迟胜强
 * @date 2018-7-10
 */
package aorey.database.config;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import aorey.database.DataTag;

public class DataConfigSelect {

    public String id = "";
    public int cache = 120;
    public String data_source = "";
    public String cache_type = "redis";
    public String class_name = "";
    public String method_name = "";
    public String sql = "";
    
    public DataConfigSelect(String configFile,HttpServletRequest request) throws DocumentException
    {
    	configFile = configFile.replace("//", "/");
        File config = new File(configFile);
        if (config.exists()) {
            SAXReader reader = new SAXReader();
            Document document = reader.read(config);
            // 根节点
            Element node = document.getRootElement();
            // sql语句的
            Element sqlNode = node.elements().get(0);
            
            this.id = sqlNode.attributeValue("id");
            this.data_source = sqlNode.attributeValue("data_source");
            if (null == sqlNode.attributeValue("cache")) {
                this.cache = -1;
            }
            else
            {
                this.cache = Integer.parseInt(sqlNode.attributeValue("cache"));
            }
            this.cache_type = sqlNode.attributeValue("cache_type");
            this.class_name = sqlNode.attributeValue("class");
            this.method_name = sqlNode.attributeValue("method");
            this.sql = sqlNode.getTextTrim();
        }
        else
        {
        	System.out.println("Error File:"+configFile);
        }
    }
}
